<template>
  <div class='cartcontrol'>
    <transition name='move'>
      <div class="decrease icon-remove_circle_outline"
           v-show='food.count>0'
           @click.stop.prevent='decreaseCart($event)'></div>
    </transition>
    <div class="count"
         v-show='
         food.count>0'>{{food.count}}</div>
    <div class="increase icon-add_circle"
         @click.stop.prevent='addCart($event)'></div>

  </div>
</template>
<script>
import Vue from 'vue'
export default {
  data () {
    return {
      balls: [{
        show: false
      },
      {
        show: false
      },
      {
        show: false
      },
      {
        show: false
      },
      {
        show: false
      }]
    }
  },
  props: {
    food: {
      type: Object
    }
  },
  created () {
  },
  methods: {
    decreaseCart (event) {
      if (!event._constructed) {
        return
      }
      if (this.food.count) { this.food.count -= 1 }
    },
    addCart (event) {
      if (!event._constructed) {
        return
      }
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
      } else {
        this.food.count += 1
      }
      this.$emit('cartadd', event.target)
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '../../common/stylus/mixin.styl'
@import '../../common/stylus/icon.styl'
@import '../../common/stylus/base.styl'
.cartcontrol
  .decrease, .count, .increase
    display inline-block
    padding 4px
  .move-enter-active, .move-leave-active
    transition all 0.4s linear
  .move-enter, .move-leave-to
    opacity 0
    transform translate3d(24px, 0, 0)
  .count
    width 24px
    height 24px
    line-height 24px
    text-align center
    font-size 10px
    vertical-align top
  .icon-remove_circle_outline, .icon-add_circle
    font-size 24px
    line-height 24px
    color rgb(0, 160, 220)
</style>
